<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
import { ROLE } from './config/constants';
import manageRoute from './router/dynamic-router'
// 解决刷新后动态路由丢失

export default {
  watch: {
    $route: {
      async handler(newVal) {
        console.log('newVal', newVal);
        const role = localStorage.getItem(ROLE);
        if (role && role === 'admin') {
          this.$router.addRoute('Layout', manageRoute);
          if (!newVal.matched.length && newVal.fullPath == '/manage') {
            await this.$router.replace('/manage');
          }
        }
      }
    }
  }
}
</script>

<style>

</style>
